package com.sweet.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.sweet.Result;
import org.springframework.cglib.core.Block;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RateLimitController {

    @GetMapping("/byResource")
    @SentinelResource(value = "byResource", blockHandler = "deal_byResource")
    public Result byResource() {
        return Result.ok("按照资源名称限流ok！(*^▽^*)");
    }

    public Result deal_byResource(BlockException blockException) {
        return Result.error("按照资源名称限流挂了o(╥﹏╥)o，服务不可用");
    }

    @GetMapping("/byUrl")
    @SentinelResource(value = "byUrl")
    public Result byUrl() {
        return Result.ok("按照路径url限流ok！(*^▽^*)");
    }
}
